﻿using System;
using System.Windows;
using Brjnk.Common;
using Brjnk.GpxExplorer.ViewModel;

namespace Brjnk.GpxExplorer.Computing
{
    public class FindPositionResult : FindResult
    {
        /// <summary>
        /// Nebližší bod stopy
        /// </summary>
        public GpsCoordinates TrackPosition { get; protected set; }

        public DateTime? Time { get; protected set; }

        /// <summary>
        /// Vzdálenost bodu od stopy
        /// </summary>
        public Distance Distance { get; protected set; }

        public FindPositionResult(IPoint previousPoint, IPoint nextPoint, double p, Distance distance)
        {
            this.PreviousPoint = previousPoint;
            this.NextPoint = nextPoint;
            this.Parameter = p;
            this.Distance = distance;
            this.TrackPosition = (GpsCoordinates)LineSegmentHelper.GetPointByParameter((Point)previousPoint.PositionI, (Point)nextPoint.PositionI, p);
            var previousPointTrk = previousPoint as TrackPointVM;
            var nextPointTrk = nextPoint as TrackPointVM;
            if (previousPointTrk != null && nextPointTrk != null && previousPointTrk.Source.Time.HasValue && nextPointTrk.Source.Time.HasValue)
                Time = previousPointTrk.Source.Time.Value.AddSeconds(((nextPointTrk.Source.Time.Value - previousPointTrk.Source.Time.Value).TotalSeconds * p));
        }
    }
}